package io.noties.markwon.plugin.uml.model

interface AdapterItem {
    var name: String
}

class AdapterItemComparator : Comparator<AdapterItem> {
    override fun compare(adapterItem: AdapterItem, t1: AdapterItem): Int {
        return adapterItem.name.compareTo(t1.name)
    }
}

//class to create "New (attribute, method, value or parameter)..." in ExpandableListView
open class AddItemString(
    override var name: String
) : AdapterItem

class MethodParameter : AdapterItem {
        override var name: String
    var parameterOrder: Int = 0
    private var mUmlType: UmlType? = null
    private var mTypeMultiplicity: TypeMultiplicity = TypeMultiplicity.SINGLE
    var arrayDimension = 1

    //    **********************************************************************************************
    //    Constructors
    //    **********************************************************************************************
    constructor(
        name: String,
        parameterOrder: Int,
        umlType: UmlType,
        typeMultiplicity: TypeMultiplicity,
        arrayDimension: Int
    ) {
        this.name = name
        this.parameterOrder = parameterOrder
        mUmlType = umlType
        mTypeMultiplicity = typeMultiplicity
        this.arrayDimension = arrayDimension
    }

    var umlType: UmlType?
        get() = mUmlType
        set(umlType) {
            mUmlType = umlType
        }
    var typeMultiplicity: TypeMultiplicity
        get() = mTypeMultiplicity
        set(typeMultiplicity) {
            mTypeMultiplicity = typeMultiplicity
        }

    //    **********************************************************************************************
    //    Test methods
    //    **********************************************************************************************
    fun isEquivalentTo(methodParameter: MethodParameter): Boolean {
        return if (mTypeMultiplicity !== TypeMultiplicity.ARRAY) mUmlType === methodParameter.mUmlType && mTypeMultiplicity === methodParameter.mTypeMultiplicity else mUmlType == methodParameter.mUmlType && mTypeMultiplicity == methodParameter.mTypeMultiplicity && arrayDimension == methodParameter.arrayDimension
    }

    companion object {
        const val JSON_METHOD_PARAMETER_NAME = "MethodParameterName"
        const val JSON_METHOD_PARAMETER_TYPE = "MethodParameterType"
        const val JSON_METHOD_PARAMETER_TYPE_MULTIPLICITY = "MethodParameterTypeMultiplicity"
        const val JSON_METHOD_PARAMETER_ARRAY_DIMENSION = "MethodParameterArrayDimension"
        const val JSON_METHOD_PARAMETER_INDEX = "MethodParameterIndex"
    }
}

enum class TypeMultiplicity {
    SINGLE, ARRAY, COLLECTION
}

class TypeNameComparator : Comparator<String> {
    override fun compare(s: String, t1: String): Int {
        if (Character.isLowerCase(s[0]) && Character.isUpperCase(t1[0])) return -1
        return if (Character.isUpperCase(s[0]) && Character.isLowerCase(t1[0])) 1 else s.compareTo(
            t1
        )
    }
}

enum class Visibility {
    PUBLIC, PROTECTED, PRIVATE
}

